﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SharpTrack.Data;
using SharpTrack.Data.Model;

namespace SharpTrack.Data.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class AttachmentTest
    {
        public AttachmentTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void Attachment_Constructors()
        {
            #region Конструктор с Id
            Guid id = Guid.NewGuid();
            string name = "Attachment name";
            byte[] content = new byte[] {0,1,2};

            Attachment attachment = new Attachment(id, name, content);

            Assert.AreNotSame(content, attachment.Content);

            Assert.AreEqual<Guid>(id, attachment.AttachmentId);

            Assert.AreEqual<string>(name, attachment.Name);

            Assert.IsNotNull(attachment.Content);
            for (int i=0; i<content.Length;i++)
            {

                Assert.IsNotNull(attachment.Content[i]);
                Assert.AreEqual<byte>(content[i], attachment.Content[i]);
            }
            #endregion

            #region Конструктор без Id
            #endregion

        }

        [TestMethod]
        public void Attachment_Size_Property()
        {
            Guid id = Guid.NewGuid();
            string name = "Attachment name";
            byte[] content = new byte[] { 0, 1, 2 };

            Attachment attachment = new Attachment(id, name, content);

            Assert.AreEqual<long>(3, attachment.Size);
        }

        [TestMethod]
        public void Attachment_Name_Property()
        {
            Guid id = Guid.NewGuid();
            string name = "Attachment name";
            byte[] content = new byte[] { 0, 1, 2 };

            Attachment attachment = new Attachment(id, name, content);

            attachment.Name = "New name";

            Assert.AreEqual<string>("New name", attachment.Name);

        }

        [TestMethod]
        public void Attachment_IsChanged_Property()
        {
            Guid id = Guid.NewGuid();
            string name = "Attachment name";
            byte[] content = new byte[] { 0, 1, 2 };

            Attachment attachment = new Attachment(id, name, content);

            Assert.IsFalse(attachment.IsChanged);

            attachment.Name = "Attachment name";

            Assert.IsFalse(attachment.IsChanged);

            attachment.Name = "Changed Name";

            Assert.IsTrue(attachment.IsChanged);

            attachment = new Attachment(name, content);

            Assert.IsTrue(attachment.IsChanged);

        }
    }
}
